package com.sams.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sams.entity.Notice;
import com.sams.entity.NoticeExample;
import com.sams.entity.Policy;
import com.sams.entity.PolicyExample;
import com.sams.entity.School;
import com.sams.entity.PolicyExample;
import com.sams.entity.PolicyExample.Criteria;
import com.sams.mapper.PolicyMapper;
import com.sams.service.PolicyService;
@Service
public class PolicyServiceImpl implements PolicyService{

	@Autowired
	private PolicyMapper mapper;
	public int add(Policy Policy) {
		// TODO Auto-generated method stub
		return mapper.insert(Policy);
	}

	public int delete(int id) {
		 //先删除文件对象  
		// 删除用户浏览 的记录 
		
		return mapper.deleteByPrimaryKey(id);
	}

	public Policy findById(int id) {
		Policy n = mapper.selectByPrimaryKey(id);
		return n;
	}

	public PageInfo<Policy> list(int currentPage,String name) {
		// 1 定义当前页  和 一页显示的行数 
		  PageHelper.startPage(currentPage, 20);  
		 
		
		  PolicyExample example = new PolicyExample();
		 Criteria createCriteria = example.createCriteria();
		 
		 if(name!=null && !name.equals("")) {
			 createCriteria.andNameLike("%"+name+"%");
		 }
		 // 2  调用查询语句
		List<Policy> list =   mapper.selectByExampleWithBLOBs(example);
		PageInfo<Policy> pageInfo = new PageInfo<Policy>(list);
		 
		return pageInfo;
	}

	public List<Policy> getList() {
		// 1 定义当前页  和 一页显示的行数 
		  PageHelper.startPage(1, 5);  
		  PolicyExample example = new PolicyExample();
			 
			 example.setOrderByClause(" createdate desc");
		 // 2  调用查询语句
		List<Policy> list =   mapper.selectByExample(example);
		PageInfo<Policy> pageInfo = new PageInfo<Policy>(list);
		
		return pageInfo.getList();
	}

}
